package sun.superstring.method1reference;

import java.util.Arrays;

public class Test1 {
    public static void main(String[] args) {
        // 目标：静态方法引用：演示一个场景。
        test();
    }

    public static void test(){
        Student[] stus = new Student[6];
        stus[0] = new Student("殷素素", 35, 171.5, '女');
        stus[1] = new Student("赵敏", 18, 168.5, '女');
        stus[4] = new Student("金毛狮王", 35, 181, '男');
        stus[2] = new Student("周芷若", 18, 172.5, '女');
        stus[3] = new Student("张无忌", 25, 170.5, '男');
        stus[5] = new Student("小昭", 19, 168.5, '女');

        // 需求：按照年龄升序排序。可以调用sun公司写好的API直接对数组进行排序
//        Arrays.sort(stus, (o1, o2) -> o1.getAge() - o2.getAge() );

//        Arrays.sort(stus, (o1, o2) -> Student.compareByAge(o1, o2) );

        // 静态方法引用： 类名：：静态方法
        Arrays.sort(stus, Student::compareByAge);

        // 遍历数组中的学生对象并输出
        for (int i = 0; i < stus.length; i++) {
            Student s = stus[i];
            System.out.println(s);
        }
    }

}
